// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.Collections;
// import java.util.List;

#include "SQLRealExpr.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/doubleEqual.h"

SQLRealExpr::SQLRealExpr()
{
}

SQLRealExpr::SQLRealExpr(double value)
    : SQLNumericLiteralExpr()
{

  this->value = value;
}

SQLRealExpr::SQLRealExpr(string_ptr  value)
    : SQLNumericLiteralExpr()
{

  this->value = atof(value->c_str());
}

SQLObject_ptr SQLRealExpr::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLRealExpr>(new SQLRealExpr(value));
  std::shared_ptr<SQLRealExpr> x = std::dynamic_pointer_cast<SQLRealExpr>(clone_tmp);
  // return new SQLRealExpr(value);
  return x;
}

//@Override
SQLObject_list_ptr  SQLRealExpr::getChildren()
{
  return SQLObject_list_ptr ();
}

//@Override
double SQLRealExpr::getNumber()
{
  return value;
}

double SQLRealExpr::getValue()
{
  return value;
}

void SQLRealExpr::setValue(double value)
{
  this->value = value;
}

void SQLRealExpr::accept0(SQLASTVisitor_ptr visitor)
{
  visitor->visit(SharedObject(SQLRealExpr));

  visitor->endVisit(SharedObject(SQLRealExpr));
}

// void SQLRealExpr::setValue(double value)
// {
//   this->value = value;
// }

//@Override
bool SQLRealExpr::equals(Object_ptr o)
{
  if (this == o.get())
  {
    return true;
  }
  if (o == nullptr || getClass() != o->getClass())
  {
    return false;
  }

  std::shared_ptr<SQLRealExpr> that = std::dynamic_pointer_cast<SQLRealExpr>(o);

  return doubleEqual::AreEqual(that->value, value);
}

//@Override
int SQLRealExpr::hashCode()
{
  return (value != +0.0f ? int(value) : 0);
}

//@Override
void SQLRealExpr::setNumber(double number)
{
  // if (number == null) {
  //     this->setValue(null);
  //     return;
  // }

  this->setValue(number);
}
